Misc cleanups for tracks and routes.
void fprintdms(FILE *, const coord *, int);
typedef void (*waypt_cb) (const waypoint *);
+typedef void (*route_hdr)(const route_head *);
+typedef void (*route_trl)(const route_head *);
void waypt_add (waypoint *);
void waypt_del (waypoint *);
void waypt_disp_all(waypt_cb);
+void route(route_hdr, route_trl, waypt_cb);
unsigned int waypt_count(void);
route_head *route_head_alloc(void);
{
fclose(ofd);
}
+
void
gpx_read(void)
{
}
}
+/*
+ *
+ */
+static
+void
+gpx_write_time(const time_t timep)
+{
+ struct tm *tm = gmtime(&timep);
+
+ fprintf(ofd, "<time>%02d-%02d-%02dT%02d:%02d:%02dZ</time>\n",
+ tm->tm_year+1900,
+ tm->tm_mon+1,
+ tm->tm_mday,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec
+ );
+
+}
+
static void
gpx_waypt_pr(const waypoint *waypointp)
{
fprintf(ofd, "<ele>\n%f\n</ele>\n",
waypointp->position.altitude.altitude_meters);
}
+ if (waypointp->creation_time) {
+ gpx_write_time(waypointp->creation_time);
+ }
if (waypointp->url) {
fprintf(ofd, "<url>%s</url>\n", waypointp->url);
}
fprintf(ofd, "</wpt>\n");
}
+static void
+gpx_track_hdr(route_head *rte)
+{
+ fprintf(ofd, "<trk>\n");
+ if (rte->rte_name) {
+ fprintf(ofd, " <name>\n");
+ fprintf(ofd, " <![CDATA[%s]]>\n",rte->rte_name);
+ fprintf(ofd, " </name>\n");
+ }
+ fprintf(ofd, "<trkseg>\n");
+}
+
+static void
+gpx_track_disp(const waypoint *waypointp)
+{
+ fprintf(ofd, "<trkpt lat=\"%lf\" lon=\"%lf\">\n",
+ waypointp->position.latitude.degrees,
+ waypointp->position.longitude.degrees);
+ if (waypointp->creation_time) {
+ gpx_write_time(waypointp->creation_time);
+ }
+ fprintf(ofd, "</trkpt>\n");
+}
+
+static void
+gpx_track_tlr(route_hdr *rte)
+{
+ fprintf(ofd, "</trkseg>\n");
+ fprintf(ofd, "</trk>\n");
+}
+
+static
+void gpx_track_pr()
+{
+ route_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp);
+}
+
void
gpx_write(void)
{
fprintf(ofd, "xmlns=\"http://www.topografix.com/GPX/1/0\"\n");
fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n");
- waypt_disp_all(gpx_waypt_pr);
+ switch(global_opts.objective) {
+ case trkdata: gpx_track_pr();
+ default:
+ case wptdata: waypt_disp_all(gpx_waypt_pr);
+ }
fprintf(ofd, "</gpx>\n");
}
mapsend_track_read();
break;
case ms_type_log:
- fatal(MYNAME ", GPS logs not supported.\n", type);
+ fatal(MYNAME ", GPS logs not supported.\n");
case ms_type_rgn:
- fatal(MYNAME ", GPS regions not supported.\n", type);
+ fatal(MYNAME ", GPS regions not supported.\n");
default:
fatal(MYNAME ", unknown file type %d\n", type);
}
void
mapsend_wpt_write(void)
{
- mapsend_hdr hdr = {13, "4D533330 MS", "30", ms_type_wpt};
+ mapsend_hdr hdr = {13, "4D533330 MS", "30", ms_type_wpt, 0};
int wpt_count = waypt_count();
int n = 0;
waypt_disp_all(mapsend_waypt_pr);
my_fwrite4(&n, mapsend_file_out);
-/* TODO: Impelment routes here */
+/* TODO: Implement routes here */
}
+#if LATER
void
mapsend_trk_write(void)
{
- mapsend_hdr hdr = {13, "4D533334 MS", "34", ms_type_track};
+ mapsend_hdr hdr = {13, "4D533334 MS", "34", ms_type_track, 0};
}
+#endif
ff_vecs_t mapsend_vecs = {
mapsend_rd_init,
}
void
-route_disp (route_head *rh)
+route_disp (const route_head *rh, waypt_cb cb )
{
queue *elem, *tmp;
- printf("NEW ROUTE\n");
+// printf("NEW ROUTE\n");
QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
waypoint *waypointp;
waypointp = (waypoint *) elem;
- waypt_disp(waypointp);
+ (*cb)(waypointp);
}
}
void
-route_disp_all()
+route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
{
queue *elem, *tmp;
QUEUE_FOR_EACH(&my_route_head, elem, tmp) {
- route_head *rh;
- rh = (route_head *) elem;
- route_disp(rh);
+ const route_head *rhp;
+ rhp = (route_head *) elem;
+ (*rh)(rhp);
+ route_disp(rhp, wc);
+ (*rt)(rhp);
}
}